//
//  UIViewController+Pop.m
//  LuxuryGoods
//
//  Created by 刘星辰 on 2018/5/20.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "UIViewController+Pop.h"
#import <objc/runtime.h>
@implementation UIViewController (Pop)
+ (UIButton *)createNavLeftBtn
{
    UIButton *btn = [[UIButton alloc]init];
    
    btn.frame = CGRectMake(0, 0, 30, 44);
    
    //    btn.titleLabel.font = TEXT_FONT_15;
    
    [btn setImage:[UIImage imageNamed:@"navfh"]
         forState:UIControlStateNormal];
    
    //    [btn setTitleColor:TEXT_COLOR_1
    //              forState:UIControlStateNormal];
    
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0);
    return btn;
}

-(void)popOrDismiss
{

    if ( self.navigationController == nil ||self.navigationController.viewControllers.count == 1 )
    {
        [self dismissViewControllerAnimated:YES completion:nil];
        
    }
    else
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

- (void)closeCurrentAndPushTo:(UIViewController *)nextVC
{
    
        NSAssert(!(self.navigationController == nil), @"老哥你的navigationController为空");
    NSMutableArray *vcArr = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
    [vcArr replaceObjectAtIndex:[vcArr indexOfObject:self] withObject:nextVC];
    [self.navigationController setViewControllers:vcArr animated:YES];
    
}

+ (instancetype)createFromXib
{
    return [[self alloc] initWithNibName:NSStringFromClass(self) bundle:nil];
}

static char leftButtonKey;
-(void)setLeftButton:(UIButton *)leftButton
{
    objc_setAssociatedObject(self, &leftButtonKey, leftButton, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

-(UIButton*)leftButton
{
    return objc_getAssociatedObject(self, &leftButtonKey);
}
@end
